package net.jlibrary.computer.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.springframework.stereotype.Component;

import net.jlibrary.common.core.annotation.CodeGenComment;
import net.jlibrary.common.core.annotation.Compositor;
import net.jlibrary.common.core.annotation.SearchCondition;
import net.jlibrary.common.core.annotation.SearchField;
import net.jlibrary.common.core.entity.BaseObject;
import net.jlibrary.student.domain.Student;

@Entity(name = "t_computers")
@Component
@CodeGenComment(value = "电脑列表", genSelect = true)
public class Computer extends BaseObject {

    private static final long serialVersionUID = 4964787706703021956L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @SearchField(value = "id", condition = SearchCondition.EQUAL)
    private Long id;

    private String name;

    private BigDecimal price;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type_id")
    @CodeGenComment(value = "电脑类型", viewList = true, viewSearch = true, required = true)
    private ComputerType type;

    @SearchField(value = "type", condition = SearchCondition.EQUAL)
    @Transient
    private ComputerType typeSearchKey;

    @Column(updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    @CodeGenComment(value = "创建时间", viewList = true)
    private Date createdate;

    @Temporal(TemporalType.TIMESTAMP)
    private Date lastdate;

    @SearchField(value = "name", condition = SearchCondition.FUZZ_FULL)
    @Transient
    private String nameSearchKey;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public ComputerType getType() {
       return type;
    }

    public void setType(ComputerType type) {
        this.type = type;
    }

    public ComputerType getTypeSearchKey() {
        return typeSearchKey;
    }

    public void setTypeSearchKey(ComputerType typeSearchKey) {
      this.typeSearchKey = typeSearchKey;
    }

    public String getNameSearchKey() {
        return nameSearchKey;
    }

    public void setNameSearchKey(String nameSearchKey) {
        this.nameSearchKey = nameSearchKey;
    }

    @Override
    public Serializable getPrimaryKey() {
        return id;
    }

    @Override
    public Date getCreatedate() {
        return createdate;
    }

    @Override
    public Date getLastdate() {
        return lastdate;
    }

    @Override
    public void setCreatedate(Date createdate) {
        this.createdate = createdate;
    }

    @Override
    public void setLastdate(Date lastdate) {
        this.lastdate = lastdate;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Student other = (Student) obj;
        if (id == null) {
            if (other.getId() != null)
                return false;
        } else if (!id.equals(other.getId()))
            return false;
        return true;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }
}
